<!DOCTYPE html>

<html>

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<title>登录</title>
	<link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="css/login.css" />
</head>

<body class="beg-login-bg">
	<div class="beg-login-box">
		<header>
			<h1>后台登录</h1>
		</header>
		<div class="beg-login-main">
			<form action="/manage/login" class="layui-form" method="post">
				<input name="__RequestVerificationToken" type="hidden" value="fkfh8D89BFqTdrE2iiSdG_L781RSRtdWOH411poVUWhxzA5MzI8es07g6KPYQh9Log-xf84pIR2RIAEkOokZL3Ee3UKmX0Jc8bW8jOdhqo81" />
				<div class="layui-form-item">
					<label class="beg-login-icon">
								<i class="layui-icon">&#xe612;</i>
						</label>
					<input type="text" name="account" lay-verify="required" autocomplete="off" placeholder="这里输入登录名" class="layui-input">
				</div>
				<div class="layui-form-item">
					<label class="beg-login-icon">
									<i class="layui-icon">&#xe642;</i>
						</label>
					<input type="password" name="password" lay-verify="required" autocomplete="off" placeholder="这里输入密码" class="layui-input">
				</div>
				<div class="layui-form-item">
					<div class="beg-pull-left beg-login-remember">
						<label>记住帐号？</label>
						<input type="checkbox" name="rememberMe" lay-filter="rememberMe" id="rememberMe" lay-skin="switch" title="记住帐号">
					</div>
					<div class="beg-pull-right">
						<button class="layui-btn layui-btn-primary" lay-submit lay-filter="login">
									<i class="layui-icon">&#xe650;</i> 登录
						</button>
					</div>
					<div class="beg-clear"></div>
				</div>
			</form>
		</div>
		<footer>
			<p>Beginner © www.huanju100.cn</p>
		</footer>
	</div>
	<script type="text/javascript" src="plugins/layui/layui.js"></script>
	<script type="text/javascript" src="js/public.js"></script>
	<script>
		layui.use(['layer', 'form'], function() {
			var layer = layui.layer,
				$ = layui.jquery,
				form = layui.form();

			var accountInput = document.querySelector("input[name='account']");
			var passwordInput = document.querySelector("input[name='password']");
			var accountCookie = getCookie("account");
			var passwordCookie = getCookie("password");
			var rememberMe = document.querySelector('div[lay-skin="_switch"]');

			if (accountCookie != null && passwordCookie != null) {
				accountInput.value = accountCookie;
				passwordInput.value = passwordCookie;
				rememberMe.setAttribute("class", "layui-unselect layui-form-switch layui-form-onswitch");
			}


			form.on('submit(login)', function(data) {
				//console.log(data);
				if (rememberMe.getAttribute("class") == "layui-unselect layui-form-switch layui-form-onswitch") {
					setCookie("account", data.field.account);
					setCookie("password", data.field.password);
				} else {
					delCookie("account");
					delCookie("password");
				}
				$.ajax({
					url: "/admin/login",
					data:{
						'account':data.field.account,
						'password':data.field.password
					},
					type: 'post',
					dataType: 'json',
					beforeSend: function() {

					},
					success: function(response) {
						if(response.code==500){
							toast(response.msg);
						}else if(response.code==200){
							toast('登陆成功');
							// if(data.field.account=="admin"){
							// 	setCookie("userType",3);
							// }else{
							// 	setCookie("userType",2);
							// }
							//setCookie("userType",response.result.roid);
							console.log(getCookie("userType"));
							location.href = "/admin/index";
						}

					}
				});
				return false;
			});
		});
	</script>
</body>

</html>
